//
//  JWDatePickerView.m
//  LiveReception
//
//  Created by SKiran on 17/2/8.
//  Copyright © 2017年 zoosnet. All rights reserved.
//

#import "JWDatePickerView.h"
#import "Colours.h"
@implementation JWDatePickerView
{
    UIView  *_pickBgView;
}

CGFloat pickerViewHeight = 260;
CGFloat toolViewHeight = 44;

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        self.hidden = YES;
        
        _bgAlphaView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, frame.size.width, frame.size.height)];
        _bgAlphaView.backgroundColor = [UIColor blackColor];
        _bgAlphaView.alpha = 0;
        [self addSubview:_bgAlphaView];
        
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(pickerViewHidden)];
        [_bgAlphaView addGestureRecognizer:tap];
        
        _pickBgView = [[UIView alloc]initWithFrame:CGRectMake(0, self.frame.size.height, self.frame.size.width, toolViewHeight + pickerViewHeight)];
        [self addSubview:_pickBgView];
        
        _toolView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, self.frame.size.width, toolViewHeight)];
        _toolView.backgroundColor = [UIColor ghostWhiteColor];
//        [_pickBgView addSubview:_toolView];
        
        _pickerBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        _pickerBtn.frame = CGRectMake(_toolView.frame.size.width - 100, 0, 100, toolViewHeight);
        [_pickerBtn setTitle:@"确定" forState:UIControlStateNormal];
        [_pickerBtn setTitleColor:TitleColor forState:UIControlStateNormal];
//        [_toolView addSubview:_pickerBtn];
        
        _cancelBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        _cancelBtn.frame = CGRectMake(15, 0, 100, toolViewHeight);
        [_cancelBtn setTitle:@"取消" forState:UIControlStateNormal];
        [_cancelBtn setTitleColor:TitleColor forState:UIControlStateNormal];
//        [_toolView addSubview:_cancelBtn];
        
        _dataPicker = [[UIDatePicker alloc]init];
        _dataPicker.frame = CGRectMake(0, toolViewHeight, self.frame.size.width, pickerViewHeight);
        _dataPicker.datePickerMode = UIDatePickerModeDate;
        _dataPicker.backgroundColor = [UIColor whiteColor];
        
        NSLocale * locale = [[NSLocale alloc] initWithLocaleIdentifier:@"Chinese"];
        [_dataPicker setLocale:locale];
        [_pickBgView addSubview:_dataPicker];
        
    }
    return self;
}

- (void)pickerViewShow {
    self.hidden = NO;
    
    [UIView animateWithDuration:animationDurations delay:0 options:0 animations:^{
        CGRect rect = _pickBgView.frame;
        rect.origin.y = self.frame.size.height - pickerViewHeight - toolViewHeight;
        _pickBgView.frame = rect;
        _bgAlphaView.alpha = 0.4;
        
    } completion:^(BOOL finished) {
        
    }];
}

- (void)pickerViewHidden {
    [UIView animateWithDuration:animationDurations delay:0 options:0 animations:^{
        CGRect rect = _pickBgView.frame;
        rect.origin.y = self.frame.size.height;
        _pickBgView.frame = rect;
        _bgAlphaView.alpha = 0;
    } completion:^(BOOL finished) {
        self.hidden = YES;
    }];
}
@end
